<template>
    <h2>录入房号信息</h2>
    <table border="1">
        <tr>
            <td>房号名称</td>
            <td>
                <input type="text" v-model="info.Room_NumberName">
            </td>
        </tr>
        <tr>
            <td>房型编号</td>
            <td>
                <select v-model="info.Room_TypeId">
                    <option :value="0">--请选择--</option>
                    <option v-for="item in roomType" :value="item.Room_TypeId">{{item.Room_TypeName}}</option>
                </select>
            </td>
        </tr>
        <tr>
            <td>房号状态</td>
            <td>
                <input type="radio" :value="true" v-model="info.Room_NumberState">上架
                <input type="radio" :value="false" v-model="info.Room_NumberState">下架
            </td>
        </tr>
        
        <tr>
            <td></td>
            <td>
                <input type="button" value="录入" @click="SaveData">
            </td>
        </tr>
        
        
    </table>
</template>
<script setup lang="ts">
import { onMounted ,ref} from "vue";
import axios from "axios";
onMounted(()=>{
    Lodata();

})

const info=ref({
    Room_NumberName:"",
    Room_TypeId:0,
    Room_NumberState:true
})



const roomType=ref([{
Room_TypeId:0,
Room_TypeName:""
}])


const Lodata=()=>{
    axios.get('https://localhost:7023/api/RoomNumber/GetRoomTypes')
    .then(res=>{
        res.data=roomType.value
    })
}


const SaveData=()=>{
    axios.post('https://localhost:7023/api/RoomNumber/AddNumber',info.value)
    .then(res=>{
        if(res.data==-1){
            alert("房号已经存在");
        }
        else if(res.data>0)
        {
            alert("录入成功");
        }
        else{
            alert("录入失败");
        }
    })
}

</script>